- /* sdodiv.cpp by K.Tsuru */
- // function ID = 333 DRADIX
- /************************************
- SDouble class
- It provides the division operator/().
- it returns m/n.
- *************************************/
- #ifndef SN_H
- #include "sn.h"
- #endif
- static const char* func = "SD /";
-
- SDouble operator/(const SDouble& m, const SDouble& n){
- if((m.Type() != m.REAL)||(n.Type() != n.REAL)){
- m.SetError(m.RADIX_ERR, func, 333);
- }
- if( n.Sign(333) == 0 ) m.SetError(m.DIVIDED_BY_ZERO, func, 333);
- if( m.Sign(333) == 0 ) return 0.0;
- if(&m == &n) return 1.0; // m/m
-
- //It checks the overflow error.
- double dExp = (double)m.RdxExp()-(double)n.RdxExp();
- if(fabs(dExp) >= DRADIX_EXP_MAX){
- if(dExp > 0) m.SetError(m.OVERFLOW_ERR,func,333);
- else m.SetError(m.UNDERFLOW_ERR,func,333);
- }
-
- /*
- When the divisor "n" can be expressed in the form n=N*10^e (|N|<m.SlOpMaxvalue())
- the division becomes as m/n = (m/N)*10^(-e).If the exponent "e" has a factor four
- (the power of DRADIX=10000),the multiplication by 10^(-e) can be done by the
- moving of figures(fixed point) or the changing of exponent(floating point).
- exsample : m/1.3=10000*(m/13000)
- Using this procedure it becomes several ten times faster if the above conversion
- is possible.
- */
- long N, e;
- if( n.ConvTolongExp(&N, &e) ){ //It can be convert into n=N*10^e?
- SDouble r;
- ulong p = (ulong)labs(N);
- if(p != 1) r = DsDiv(m, p); // r = m/|N|
- else r = m;
- //In the fixed point mode it maybe become r=0.
- if( r.Sign(333) ){
- r.SetSign(m.Sign()*n.Sign());
- if(e) r.MultPow10(-e); // r = m*10^(-e)/|N| = m/|n|
- }
- return r;
- }
- return m*DReciprocal(n); // m*(1/n)
- }
sdodiv.cpp : last modifiled at 2015/11/25 20:17:06(1,678 bytes)
created at 2017/10/07 10:21:14
The creation time of this html file is 2017/10/07 10:30:03 (Sat Oct 07 10:30:03 2017).